package com.kotlin.lib.coroutines

import kotlinx.coroutines.*
import java.io.IOException

fun main() = runBlocking<Unit> {
    val handler = CoroutineExceptionHandler { coroutineContext, throwable ->
        println("coroutine exception:$throwable")
    }

    val launch = GlobalScope.launch(handler) {
        val inner = launch {
            launch {
                throw IOException()
            }
        }

        try {
            inner.join()
        } catch (e: CancellationException) {
            println("rethrowing CancellationException")
            throw e
        }
    }
    launch.join()

}